package com.qiantu.api.db;

import android.content.Context;

import com.qiantu.api.db.database.LocalDataBase;
import com.qiantu.api.db.greendao.MusicDaoBeanDao;
import com.qiantu.api.entity.MusicDaoBean;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class LLMusicDBManager {

    private final String TAG = "LLMusicDBManager";
    private volatile static LLMusicDBManager instance = null;
    private final static Object object = new Object();
    private final MusicDaoBeanDao musicDaoBeanDao;
    private Context context;

    private LLMusicDBManager(Context context) {
        this.context = context;
        musicDaoBeanDao = LocalDataBase.getInstance().getDaoSession(context).getMusicDaoBeanDao();
    }

    public static LLMusicDBManager getInstance(Context context) {
        if (instance == null) {
            synchronized (object) {
                if (instance == null) {
                    instance = new LLMusicDBManager(context.getApplicationContext());
                }
            }
        }
        return instance;
    }

    public void insertMusic(ArrayList<MusicDaoBean> musicDaoBeans) {
        for (MusicDaoBean musicDaoBean : musicDaoBeans) {
            putbean(musicDaoBean);
        }
    }

    public void putbean(MusicDaoBean musicDaoBeans) {
        musicDaoBeanDao.save(musicDaoBeans);
    }

    public List<MusicDaoBean> getmusicbean(){
        return musicDaoBeanDao.loadAll();
    }

    public void deleteAll(){
        musicDaoBeanDao.deleteAll();

    }
}
